import { reqGetDetail } from "@/api/index"
const state = {
    goodInfo: {}
}
const mutations = {
    updateGoodinfo(state, newGoodinfo) {
        state.goodInfo = newGoodinfo
    }
}
const actions = {
    async setDetailGoodinfo(context, paramsGood) {
        const res = await reqGetDetail()
        console.log(paramsGood);
        res.data.data
        const newGoodinfo = res.data.data.find(item => item.categoryView && item.categoryView.id == paramsGood);
        context.commit('updateGoodinfo', newGoodinfo)
    }
}

//简化数据而生
const getters = {
    //路径导航简化的数据
    categoryView(state) {
        return state.goodInfo.categoryView || {}
    },
    //简化产品信息的数据 商品右边，和放大镜的小窗的数据
    skuInfo() {
        return state.goodInfo.skuInfo || {}
    },
    //产品售卖属性的简化
    spuSaleAttrList(){
        return state.goodInfo.spuSaleAttrList || []
    }
}
export default {
    namespaced: true,
    state,
    mutations,
    actions,
    getters
}